// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程：https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129
const db = uniCloud.databaseForJQL()
module.exports = {
	_before: function() { // 通用预处理器

	},


	async goodsList(query) {
		const id = query.cid
		const threeCategories = db.collection("threeCategories").where(`_id=="${id}"`).field(
			"_id").getTemp()
		const goods = db.collection("uni-cms-articles")
			.where("article_status==1")
			.field(
				"category_id,price as goods_price ,arrayElemAt(thumbnail, 0) as goods_small_logo,title as goods_name"
			).orderBy("publish_date desc").skip(query.pagenum * query.pagesize).limit(query.pagesize)
			.getTemp()

		const goodsList = await db.collection(threeCategories, goods).get()

		const goodsListCount = await db.collection("uni-cms-articles")
			.where("article_status==1" && `category_id=="${id}"`)
			.count()

		return {
			"goods": goodsList.data[0]._id["uni-cms-articles"],
			"total": goodsListCount.total,
		}



	}

	/**
	 * method1方法描述
	 * @param {string} param1 参数1描述
	 * @returns {object} 返回值描述
	 */
	/* 
	
	
	method1(param1) {
		// 参数校验，如无参数则不需要
		if (!param1) {
			return {
				errCode: 'PARAM_IS_NULL',
				errMsg: '参数不能为空'
			}
		}
		// 业务逻辑
		
		// 返回结果
		return {
			param1 //请根据实际需要返回值
		}
	}
	*/
}